import {createApp} from 'vue'
import App from '@/App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/theme-chalk/index.css'
import router from '@/router/index'
import i18n from "@/utils/i18n";
import axios from "@/utils/axios";
import {localEnv} from '@/utils/setBaseUrl' // 配置文件
import '@/utils/common.js' // 公共方法
import '@/utils/permission.js' // 路由权限设置
import '@/utils/rules.js' // 表单验证规则
import '@/assets/css/theme.css' // 主题css
import '@/assets/css/common.css' // 公共css
import '@/assets/icon/iconfont.css'
import moment from 'moment'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'

const vue = createApp(App);
vue.use(ElementPlus, {
    locale: zhCn,
})
    .use(router)
    .use(i18n)
    .mount('#app')
if (localEnv !== 'prod') {
    vue.config.devtools = true
}
vue.config.globalProperties.$ajax = axios;
vue.config.globalProperties.$moment = moment;


const debounce = (fn, delay) => {
    let timer = null;
    return function () {
        let context = this;
        let args = arguments;
        clearTimeout(timer);
        timer = setTimeout(function () {
            fn.apply(context, args);
        }, delay);
    }
}

// 暂时处理 el-table 渲染问题
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver{
    constructor(callback) {
        callback = debounce(callback, 16);
        super(callback);
    }
}
